﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBControl;
using System.Data.SqlClient;

namespace ProjectX
{
    public partial class allbuy :Errorbase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getTotalCount();
                bindview();
                bindpassview();

                if (Session["userNick"] != null)
                {
                    this.username.Text = Session["userNick"].ToString();
                    this.loginlink.Visible = false;
                    this.reglink.Visible = false;
                    this.logout.Visible = true;
                }
            }
        }

        private void getTotalCount()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlcount = "SELECT COUNT(*) FROM BuyersinfoR WHERE [Status] = 0";
            string sqlpasscount = "SELECT COUNT(*) FROM BuyersinfoR WHERE [Status] = 1";
            this.AspNetPager.RecordCount = int.Parse(sdh.ExecuteScalar(sqlcount).ToString());
            this.passPager.RecordCount = int.Parse(sdh.ExecuteScalar(sqlpasscount).ToString());
        }

        private void bindview()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlwhere = " WHERE [Status] = 0";

            SqlParameter p1 = new SqlParameter("@tablename", "BuyersinfoR");//视图名或表名
            SqlParameter p2 = new SqlParameter("@pagerow", this.AspNetPager.PageSize);         //每页显示记录数 
            SqlParameter p3 = new SqlParameter("@pagenow", this.AspNetPager.CurrentPageIndex); //当前显示第几页 
            SqlParameter p4 = new SqlParameter("@ordercol", "Starttime");//排序字段
            SqlParameter p5 = new SqlParameter("@order", 1);//排序顺序，0升序，1降序
            SqlParameter p6 = new SqlParameter("@where", sqlwhere);


            SqlParameter[] paras = new SqlParameter[] { p1, p2, p3, p4, p5, p6 };

            this.baobeiView.DataSource = sdh.ExecuteDataTable("sp_page", System.Data.CommandType.StoredProcedure, null, paras);

            this.baobeiView.DataBind();
        }

        private void bindpassview()
        {
            SqlDbHelper sdh = new SqlDbHelper();
            string sqlwhere = " WHERE [Status] = 1";

            SqlParameter p1 = new SqlParameter("@tablename", "BuyersinfoR");//视图名或表名
            SqlParameter p2 = new SqlParameter("@pagerow", this.passPager.PageSize);         //每页显示记录数 
            SqlParameter p3 = new SqlParameter("@pagenow", this.passPager.CurrentPageIndex); //当前显示第几页 
            SqlParameter p4 = new SqlParameter("@ordercol", "Starttime");//排序字段
            SqlParameter p5 = new SqlParameter("@order", 1);//排序顺序，0升序，1降序
            SqlParameter p6 = new SqlParameter("@where", sqlwhere);


            SqlParameter[] paras = new SqlParameter[] { p1, p2, p3, p4, p5, p6 };

            this.passView.DataSource = sdh.ExecuteDataTable("sp_page", System.Data.CommandType.StoredProcedure, null, paras);

            this.passView.DataBind();
        }

        protected void AspNetPager_PageChanged(object sender, EventArgs e)
        {
            bindview();
            ScriptManager.RegisterStartupScript(AspNetPager, this.GetType(), "resizeimg", "<script>ResizeImg();</script>", false);
        }

        protected void passPager_PageChanged(object sender, EventArgs e)
        {
            bindpassview();
            ScriptManager.RegisterStartupScript(passPager, this.GetType(), "resizeimg", "<script>ResizeImg();</script>", false);
            ScriptManager.RegisterStartupScript(passPager, this.GetType(), "showContent2", "<script>$('#Content2').show();$('#Content1').hide();</script>", false);
        }

        protected void logout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Response.Write("<script language='javascript'>window.parent.location.href='/'</script>");
        }
    }
}